<?php
/**
 * Created by PhpStorm.
 * User: WangXiaoHong
 * Date: 15-11-24
 * Time: 下午3:33
 */
/**获取ip地址**/
function getip(){
    if(!empty($_SERVER["HTTP_CLIENT_IP"])){
        $cip = $_SERVER["HTTP_CLIENT_IP"];
    }
    elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
        $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    }
    elseif(!empty($_SERVER["REMOTE_ADDR"])){
        $cip = $_SERVER["REMOTE_ADDR"];
    }
    else{
        $cip = "无法获取！";
    }
    return $cip;
}
/***记录信息到文件中***/
function err($txt,$ip,$file){
    $filepath= $file;
    $word = date("Y-m-d H:i:s")."|".$txt.'|'.$ip;
    if(file_exists($filepath)){
        $maxsize  = 1024*1024*10;
        $filesize = filesize($filepath);
        $filetype = end(explode(".",$filepath));
        $filename = substr($filepath,0,strpos($filepath,'.'));
        if($filesize>$maxsize)
            rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
    }
    $fp = fopen($filepath,"a");
    flock($fp, LOCK_EX);
    fwrite($fp,$word."\n");
    flock($fp, LOCK_UN);
    fclose($fp);
}
/***返回数据****/
function ret_json($status,$orderId,$coupon,$ext=""){
    $return=array(
        'status'  =>$status,
        'orderId' =>$orderId,
        'coupon'  =>$coupon,
        'ext'     =>$ext
    );
    echo json_encode($return);
}
/***取消订单返回数据****/
function cancel_json($status){
    $return=array(
        'status'  =>$status,
    );
    echo json_encode($return);
}